package com.study.springmvc.web.module.controller.user;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Validator;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.study.springmvc.biz.module.common.Result;
import com.study.springmvc.biz.module.user.ApplyVO;
import com.study.springmvc.dal.dataobject.operation.ServersDO;
import com.study.springmvc.service.operation.OperationService;
import com.study.springmvc.web.module.controller.BaseController;

@Controller
public class OperationController extends BaseController {
    @Autowired
    private Validator        validator;
    @Autowired
    private OperationService operationService;

    @RequestMapping(value = "/server.htm")
    public String serverList(ModelMap map, String id) {
        Result result = operationService.getAllServers();
        if (result.isSuccess()) {
            map.addAttribute("servers", (Collection<ServersDO>) result.getVoucher());
        } else {
            map.addAttribute("errMsg", result.getFailureDetail());
            if (logger.isInfoEnabled()) {
                logger.info(result.getFailureDetail().toString());
            }
        }
        return "/serverList";
    }

    @RequestMapping(value = "/apply.htm", method = RequestMethod.GET)
    public String apply(ModelMap map) {
        return "apply";
    }

    @RequestMapping(value = "/apply.htm", method = RequestMethod.POST)
    public String processApply(ApplyVO applyVO, BindingResult bindingResult, ModelMap map) {
        return "applyList";
    }
}
